package com.example.village.service.impl;

import com.example.village.dao.NeighbourhoodDao;
import com.example.village.entity.NeighbourhoodEntity;
import com.example.village.entityVO.UserVO;
import com.example.village.service.NeighbourhoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NeighbourhoodImpl implements NeighbourhoodService {

    @Autowired
    private NeighbourhoodDao neighbourhoodDao;

    @Override
    public List<NeighbourhoodEntity> queryByDim(String word) {
        return neighbourhoodDao.queryByDim(word);
    }

    @Override
    public List<NeighbourhoodEntity> selectByParam(NeighbourhoodEntity neighbourhoodEntity) {
        return neighbourhoodDao.selectByParam(neighbourhoodEntity);
    }

    @Override
    public boolean insert(NeighbourhoodEntity neighbourhoodEntity) {
        return neighbourhoodDao.insert(neighbourhoodEntity) > 0;
    }

    @Override
    public boolean update(NeighbourhoodEntity neighbourhoodEntity) {
        return neighbourhoodDao.update(neighbourhoodEntity) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return neighbourhoodDao.delete(id) > 0;
    }

    @Override
    public boolean deleteMore(List<Integer> ids) {
        if (neighbourhoodDao.deleteMore(ids) > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<UserVO> querySelect() {
        return neighbourhoodDao.querySelect();
    }

    @Override
    public NeighbourhoodEntity queryById(Integer id) {
        return neighbourhoodDao.queryById(id);
    }

    @Override
    public List<UserVO> querySelectByParam(String param) {
        List<UserVO> userVOS = neighbourhoodDao.querySelectParam(param);
        if (!(userVOS.size() > 0)) {
            return null;
        }
        for (UserVO u : userVOS) {
            String address = u.getLabel();
            address = address.substring(address.indexOf("|") + 1);
            u.setLabel(address);
        }
        return userVOS;
    }
}
